package routes

import (
	"github.com/gin-gonic/gin"
	"net/http"
	"pharymacy-management-system/controller"
	"pharymacy-management-system/logger"
	"pharymacy-management-system/middlewares"
)

func SetUp() *gin.Engine {
	r := gin.New()
	r.Use(logger.GinLogger(), logger.GinRecovery(true))

	// 设置gin请求路径前缀
	prefix := "/api"
	// 注册业务路由
	r.POST(prefix+"/signup", controller.SignUpHandler)

	r.POST(prefix+"/login", controller.LoginHandler)

	r.GET(prefix+"/user/info", middlewares.JWTAuthMiddleware(), controller.InfoHandler)

	r.POST(prefix+"/user/update/:nickname", middlewares.JWTAuthMiddleware(), controller.UpdateNickNameHandler)

	r.GET(prefix+"/user/list", middlewares.JWTAuthMiddleware(), controller.GetUserListHandler)

	r.GET(prefix+"/user/all", middlewares.JWTAuthMiddleware(), controller.GetAllUser)

	r.POST(prefix+"/user/delete/:userID", middlewares.JWTAuthMiddleware(), controller.DeleteUserHandler)

	r.GET(prefix+"/drug/type/all", middlewares.JWTAuthMiddleware(), controller.GetAllDrugType)

	r.POST(prefix+"/drug/type/update", middlewares.JWTAuthMiddleware(), controller.UpdateDrugTypeName)

	r.POST(prefix+"/drug/type/add/:typename", middlewares.JWTAuthMiddleware(), controller.AddDrugType)

	r.GET(prefix+"/drug/all", middlewares.JWTAuthMiddleware(), controller.GetAllDrug)

	r.POST(prefix+"/drug/add", middlewares.JWTAuthMiddleware(), controller.AddDrug)

	r.POST(prefix+"/drug/update", middlewares.JWTAuthMiddleware(), controller.UpdateDrug)

	r.POST(prefix+"/stock/operate/add/:operateName", middlewares.JWTAuthMiddleware(), controller.AddStockOperate)

	r.GET(prefix+"/stock/operate/all", middlewares.JWTAuthMiddleware(), controller.GetAllStockOperate)

	r.POST(prefix+"/stock/operate/update", middlewares.JWTAuthMiddleware(), controller.UpdateStockOperate)

	r.POST(prefix+"/stock/add", middlewares.JWTAuthMiddleware(), controller.AddStock)

	r.GET(prefix+"/stock/all", middlewares.JWTAuthMiddleware(), controller.GetAllStock)

	r.POST(prefix+"/stock/update", middlewares.JWTAuthMiddleware(), controller.UpdateStock)

	r.GET(prefix+"/stock/history/all", middlewares.JWTAuthMiddleware(), controller.GetAllStockHistory)

	r.GET(prefix+"/stock/history/:stockId", middlewares.JWTAuthMiddleware(), controller.GetStockHistoryByStockId)

	r.GET(prefix+"/sales/status/all", middlewares.JWTAuthMiddleware(), controller.GetAllSaleStatus)

	r.POST(prefix+"/sales/status/add/:statusName", middlewares.JWTAuthMiddleware(), controller.AddSaleStatus)

	r.POST(prefix+"/sales/status/update", middlewares.JWTAuthMiddleware(), controller.UpdateSaleStatus)

	r.POST(prefix+"/sales/add", middlewares.JWTAuthMiddleware(), controller.AddSales)

	r.POST(prefix+"/sales/approve/:orderID/:statusID", middlewares.JWTAuthMiddleware(), controller.ApproveSales)

	r.POST(prefix+"/sales/exec/:orderID/:statusID", middlewares.JWTAuthMiddleware(), controller.ExecSales)

	r.POST(prefix+"/sales/settlement/:orderID/:statusID", middlewares.JWTAuthMiddleware(), controller.SettlementSales)

	r.GET(prefix+"/sales/:statusID/all", middlewares.JWTAuthMiddleware(), controller.GetAllSalesByStatus)

	r.GET(prefix+"/sales/order/:orderID", middlewares.JWTAuthMiddleware(), controller.GetSalesByOrderID)

	r.GET(prefix+"/vip/all", middlewares.JWTAuthMiddleware(), controller.GetAllVip)

	r.POST(prefix+"/vip/add/:userID", middlewares.JWTAuthMiddleware(), controller.AddVip)

	r.POST(prefix+"/vip/update/:userID/:number/:description", middlewares.JWTAuthMiddleware(), controller.UpdateVip)

	r.GET(prefix+"/vip/history/:vipID", middlewares.JWTAuthMiddleware(), controller.GetVipHistoryListByVipID)

	r.GET(prefix+"/ping", middlewares.JWTAuthMiddleware(), func(c *gin.Context) {
		c.String(http.StatusOK, "pong")
	})

	r.NoRoute(func(c *gin.Context) {
		c.JSON(http.StatusOK, gin.H{
			"code": 404,
			"msg":  "404",
		})
	})
	return r
}
